import params from "./params.js"
import req from "./request.js"
import noti from "./notification.js"

export default{
	install(Vue){
		Vue.prototype.$req = req
		Vue.prototype.$params = params
		Vue.prototype.$noti = noti
		Vue.prototype.$formatTime = date =>{
			const formatNumber = n =>{
				n = n.toString()
				return n[1] ? n : `0${n}`
			}
			const year = date.getFullYear()
			const month = date.getMonth() + 1 
			const day = date.getDate()
			const hour = date.getHours()
			const minutes = date.getMinutes()
			const seconds = date.getSeconds()
			return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minutes, seconds].map(formatNumber).join(':')}`
		}
		Vue.prototype.$checkLen = (field, len, name) => {
			if(field.length >= len){
				return true
			}
			let msg = name + "不能少于" + len + "个字符"
			if(field.length == 0){
				msg = name + "不能为空"
			}
			uni.showToast({
				title: msg,
				icon: "none"
			})
			return false
		}
	}
}